package com.xunqi.sell.handler;

import com.xunqi.sell.VO.ResultVO;
import com.xunqi.sell.exception.ResponseBankException;
import com.xunqi.sell.exception.SellException;
import com.xunqi.sell.exception.SellerAuthorizeException;
import com.xunqi.sell.util.ResultVOUtil;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Jerry
 */
@ControllerAdvice
public class SellExceptionHandler {

    /**
     *  拦截登录异常
     * @return
     */
    @ExceptionHandler(value = SellerAuthorizeException.class)
    public ModelAndView handlerSellerAuthorizeException() {
        return new ModelAndView("redirect:http://hjl.mynatapp.cc".concat("/sell/wechat/qrAuthorize")
        .concat("?returnUrl=")
        .concat("http://hjl.mynatapp.cc")
        .concat("/sell/seller/login"));
    }


    @ExceptionHandler(value = SellException.class)
    @ResponseBody
    public ResultVO handlerSellerException(SellException e) {
        return ResultVOUtil.error(e.getCode(),e.getMessage());
    }


    @ExceptionHandler(value = ResponseBankException.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public void handleResponseBankException() {

    }

}
